/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GuiBuscarLocacoesRelatorio.java
 *
 * Created on 28/11/2011, 16:10:31
 */
package view.gui;

import controller.ControllerRelatorio;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author Rodrigo
 */
public class GuiBuscarLocacoesRelatorio extends JInternalFramePermissao {

    /** Creates new form GuiBuscarLocacoesRelatorio */
    public GuiBuscarLocacoesRelatorio() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        localizarCliente = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        dataFinal = new javax.swing.JFormattedTextField();
        dataInicial = new javax.swing.JFormattedTextField();

        setClosable(true);
        setTitle("Relatório de Locações");
        getContentPane().setLayout(null);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Filtros de busca"));
        jPanel1.setLayout(null);

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText(" a ");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(190, 30, 30, 30);

        localizarCliente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/imagens/Search-icon.png"))); // NOI18N
        localizarCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                localizarClienteActionPerformed(evt);
            }
        });
        jPanel1.add(localizarCliente);
        localizarCliente.setBounds(350, 20, 40, 40);

        jLabel2.setText("Período:");
        jPanel1.add(jLabel2);
        jLabel2.setBounds(20, 30, 60, 30);

        try {
            dataFinal.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jPanel1.add(dataFinal);
        dataFinal.setBounds(220, 30, 110, 30);

        try {
            dataInicial.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        jPanel1.add(dataInicial);
        dataInicial.setBounds(80, 30, 110, 30);

        getContentPane().add(jPanel1);
        jPanel1.setBounds(0, 0, 410, 80);

        setBounds(0, 0, 427, 114);
    }// </editor-fold>//GEN-END:initComponents

    private void localizarClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_localizarClienteActionPerformed
        JasperPrint relat = ControllerRelatorio.relatorioLocacoes(dataInicial.getText(), dataFinal.getText());
        if (!relat.getPages().isEmpty()) {
            JasperViewer.viewReport(relat, false);
            this.dispose();
        } else {
            JOptionPane.showMessageDialog(null, "Não foram encontrados dados para esse periodo.", "Falha.", JOptionPane.ERROR_MESSAGE);
        }
}//GEN-LAST:event_localizarClienteActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFormattedTextField dataFinal;
    private javax.swing.JFormattedTextField dataInicial;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton localizarCliente;
    // End of variables declaration//GEN-END:variables

    @Override
    public int getPermissao() {
        return 26;
    }
}
